package com.binarysearch;

public class Solution275 {
    public int hIndex(int[] citations) {
        int i = 0;
        int j = citations.length - 1;
        int len = citations.length;
        while (i <= j) {
            int mid = (i + j) >> 1;
            if (len - mid == citations[mid]) return citations[mid];
            else if (len - mid > citations[mid]) i = mid + 1;
            else j = mid - 1;
        }
        return -1;
    }
}
